﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Orchard.Environment.Extensions;

namespace MediaGarden.Images.Galleries
{
    [OrchardFeature("MediaGarden.Images.Galleries")]
    public class Migrations : DataMigrationImpl
    {

        public int Create()
        {
            ContentDefinitionManager.AlterTypeDefinition("Gallery", cfg => cfg
                .WithPart("CommonPart")
                .WithPart("SocketsPart")
                .Creatable()
                );

            ContentDefinitionManager.AlterTypeDefinition("GalleryToMedia", cfg => cfg
                .WithPart("CommonPart")
                .WithPart("SequencePart")
                            //         .WithPart("ImageViewportPart")
                .WithPart("ConnectorPart", part => part
                    .WithSetting("ConnectorTypePartSettings.AllowedContentLeft", "Gallery")
                    .WithSetting("ConnectorTypePartSettings.AllowedContentRight", "Image")
                    .WithSetting("ConnectorTypePartSettings.AllowMany", "true")
                    .WithSetting("ConnectorTypePartSettings.InverseConnectorType", "Media")
                    ));

            ContentDefinitionManager.AlterTypeDefinition("MediaToGallery", cfg => cfg
                .WithPart("CommonPart")
                .WithPart("ConnectorPart", part => part
                    .WithSetting("ConnectorTypePartSettings.AllowedContentRight", "Gallery")
                    .WithSetting("ConnectorTypePartSettings.AllowedContentLeft", "Image")
                    .WithSetting("ConnectorTypePartSettings.AllowMany", "true")
                    .WithSetting("ConnectorTypePartSettings.InverseConnectorType", "GalleryToMedia")
                    .WithSetting("ConnectorTypePartSettings.SocketDisplayName", "Galleries")
                    ));
            return 1;
        }

    }

}